﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include "RBTree.hpp"
#include "AVLTree.hpp"

using namespace std;
using namespace Yohifo;

void RBTreeTest1()
{
	//vector<int> v = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	vector<int> v = { 42,30,81,68,63,84,27,53,77,82,38,19,21};
	RBTree<int, int> rb;
	for (auto e : v)
	{
		if (e == 14)
		{
			int x = 10;
		}

		rb.Insert(make_pair(e, e));
		cout << e << " | " << rb.IsRBTree() << endl;
	}

	cout << rb.IsRBTree() << endl;
}

void RBTreeTest2()
{
	srand((size_t)time(NULL));

	AVLTree<int, int> av;
	RBTree<int, int> rb;

	int begin1, begin2, end1, end2, time1 = 0, time2 = 0;

	int n = 100000;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		int val = (rand() + i) * sum;
		sum ++;

		begin1 = clock();
		av.Insert(make_pair(val, val));
		end1 = clock();
		
		begin2 = clock();
		rb.Insert(make_pair(val, val));
		end2 = clock();

		time1 += (end1 - begin1);
		time2 += (end2 - begin2);
	}

	cout << "插入 " << sum << " 个数据后" << endl;
	cout << "AVLTree 耗时: " << time1 << "ms" << endl;
	cout << "RBTree 耗时: " << time2 << "ms" << endl;
	cout << "=================================" << endl;
	cout << "AVLree: " << av.IsAVLTree() << " | " << "高度：" << av.getHeight() << endl;
	cout << "RBTree: " << rb.IsRBTree() << " | " << "高度：" << rb.getHeight() << endl;
}

int main()
{
	RBTreeTest2();
	return 0;
}